package com.choosefine.paycenter.config;

/**
 * Comments：
 * Author：Jay Chang
 * Create Date：2017/5/10
 * Modified By：
 * Modified Date：
 * Why & What is modified：
 * Version：v1.0
 */

import com.choosefine.common.url.UrlRegistrar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class RegistToAuthSysBeanConfig {

    @Value("${dmsUrl}")
    final String dmsUrl = null;

    @Value("${server.context-path}")
    final String serviceName = null;

    @Autowired
    CommonProperties commonProperties;

    @Bean
    public UrlRegistrar urlRegistrar(RequestMappingHandlerMapping requestMappingHandlerMapping, RestTemplate restTemplate) {
        // 在设定了dmsUrl的情况下，去注册URLs
        if (!StringUtils.isEmpty(dmsUrl) && dmsUrl.startsWith("http")) {
            return new UrlRegistrar(requestMappingHandlerMapping, restTemplate, serviceName, dmsUrl, commonProperties.getIgnoreUrls());
        }

        return null;
    }

    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        return new RequestMappingHandlerMapping();
    }
}